﻿using UnityEngine;
using System.Collections;
using LitJson;


public class LoadMap : MonoBehaviour
{
    void Start()
    {
        var mapJson = new JsonData();
        for (var i = 0; i < mapJson.Count; i++)
        {
            var tob = Instantiate((GameObject)Resources.Load(mapJson[i]["type"].ToString()));
            tob.name = mapJson[i]["type"].ToString() + mapJson[i]["id"].ToString();
            tob.transform.position = mapJson[i]["pos"].ToVector3();
            tob.transform.rotation = Quaternion.Euler(mapJson[i]["rotation"].ToVector3());
            tob.transform.localScale = mapJson[i]["scale"].ToVector3();
            switch (mapJson[i]["type"].ToString())
            {
                case "Enmey":
                    tob.GetComponentInChildren<EnemyAI>().speed = mapJson[i]["EnemyAI"]["speed"].ToFloat();
                    tob.GetComponentInChildren<EnemyAI>().pathPoses = mapJson[i]["EnemyAI"]["pathPoses"].ToListVector3();
                    tob.GetComponentInChildren<EnemySight>().sightAngle = mapJson[i]["EnemyAI"]["sightAngle"].ToFloat();
                    tob.GetComponentInChildren<EnemySight>().stepDegree = mapJson[i]["EnemyAI"]["stepDegree"].ToFloat();
                    tob.GetComponentInChildren<EnemySight>().sightDistance = mapJson[i]["EnemyAI"]["sightDistance"].ToFloat();
                    break;
            }
        }

    }
}
